package com.yc.jpyy.rentalcarcompany.service.imp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.rentalcarcompany.dao.RentalCarCompanyDao;
import com.yc.jpyy.rentalcarcompany.service.RentalCarCompanyService;


@Service
public class RentalCarCompanyServiceImpl extends BaseService implements RentalCarCompanyService {
 

@Autowired
private RentalCarCompanyDao rentalCarCompanyDao;

@Override
public Map<String, Object> addRentalCarCompany(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int count = rentalCarCompanyDao.addRentalCarCompany(paramsMap);
	if(count <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "新增失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "新增成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> selectRentalCarCompanyByPages(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
	paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
	String status = Optional.ofNullable(paramsMap.get("status")).orElse("").toString();
	paramsMap.put("status", status.equals("")?"":status.split(","));
	List<Map<String,Object>> list = rentalCarCompanyDao.selectRentalCarCompanyByPages(paramsMap);
	int counts = rentalCarCompanyDao.selectRentalCarCompanyCount(paramsMap);
	if(list != null && list.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",list);
		resultMap.put("TotalCount",counts);
		resultMap.put("TotalPage",counts % pagesize >0 ? counts/pagesize + 1 : counts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}


@Override
public Map<String, Object> updateRentalCarCompany(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = rentalCarCompanyDao.updateRentalCarCompany(paramsMap);
	if(i > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "修改成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "修改失败");
	}
	return resultMap;
}

@Override
public Map<String, Object> selectRentalCarCompanyById(
		Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> map = rentalCarCompanyDao.selectRentalCarCompanyById(paramsMap);
	if(map != null && map.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "查询成功");
		resultMap.put("ListData",map);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

}
